<?php
/**
 * Description: eeo客户端测试获取url
 * User: devforma
 * Date: 2016/11/11
 * Time: 12:18
 */

require LIB_DIR . '/EEOAPI.php';

class EeoTestUrl implements iController {

    /**
     * api请求处理主函数
     * @param array $queryArgs 就是$_REQUEST变量
     * @return array api返回结果，必须含response_code
     */
    public function output($queryArgs) {
        global $cmsdb, $uddb;

        if (validateUser($queryArgs) !== 1 || empty($queryArgs['test_id']) || filter_var($queryArgs['test_id'], FILTER_VALIDATE_INT) === false) {
            return genOutput(1000);
        }

        $phone = $uddb->getVar('SELECT `phone` FROM `user_auth_info` WHERE `ID`=:uid', [':uid' => $queryArgs['user_id']]);
        if (empty($phone))
            return genOutput(1001);

        //获取eeo测试课程
        $testInfo = $cmsdb->getVar('SELECT t.eeo_test_course FROM educms.data_teacher AS t INNER JOIN userdata.eeo_client_test AS e ON t.id=e.teacher_id WHERE e.id=:eid AND e.status=2', [':eid' => $queryArgs['test_id']]);
        if (empty($testInfo))
            return genOutput(1001);

        $testInfo = explode('_', $testInfo);
        $eeoCourseId = $testInfo[1];
        $eeoClassId = $testInfo[2];

        //生成eeo客户端唤起url
        $eeo = new EEO();
        $url = $eeo->getClassEntryUrl($eeoCourseId, $eeoClassId, $phone);

        return empty($url) ? genOutput(1001) : genOutput(1, ['url' => $url]);
    }
}